local mingshenganwen = fk.CreateSkill {
  name = "lingling__mingshenganwen",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lingling__mingshenganwen"] = "民生安稳",
  [":lingling__mingshenganwen"] = "锁定技，你的手牌上限至少为4。若你没有装备宝物牌，你视为装备着【浑天仪】。",
}

mingshenganwen:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(mingshenganwen.name) and player.phase == Player.Judge and not player:getEquipment(Card.SubtypeTreasure) and
      not player:isAllNude() and Fk.skills["#ling__armillary_sphere_skill"] and Fk.skills["#ling__armillary_sphere_skill"]:isEffectable(player) and #player:getAvailableEquipSlots(Card.SubtypeTreasure) > 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local cards = room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = "#ling__armillary_sphere_skill",
      prompt = "#ling__armillary_sphere-invoke",
      cancelable = true,
      expand_pile = player:getCardIds("j"),
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:recastCard(event:getCostData(self).cards, player, "#ling__armillary_sphere_skill")
  end,
})

mingshenganwen:addEffect("maxcards", {
  correct_func = function(self, player)
    if player:hasSkill(mingshenganwen.name) then
      local baseValue = math.max(player.hp, 0) --玩家的基础手牌上限
      local status_skills = Fk:currentRoom().status_skills[MaxCardsSkill] or Util.DummyTable
      local max_fixed = nil
      for _, skill in ipairs(status_skills) do
        if skill ~= self then
          local f = skill:getFixed(player)
          if f ~= nil then
            max_fixed = max_fixed and math.max(max_fixed, f) or f
          end
        end
      end
      if max_fixed then baseValue = math.max(max_fixed, 0) end
      for _, skill in ipairs(status_skills) do
        if skill ~= self then
          local c = skill:getCorrect(player)
          baseValue = baseValue + (c or 0)
        end
      end
      if 4 > baseValue then
        return 4 - baseValue
      end
    end
  end,
})

mingshenganwen:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#ling__armillary_sphere_skill")
end)

return mingshenganwen
